#include "LPC11XX.H"
#define LED1_ON() (LPC_GPIO2->DATA &= ~(1<<0))
#define LED1_OFF() (LPC_GPIO2->DATA |=(1<<0))
unsigned int status;
static volatile unsigned int ticks = 0;

void LedInit(void)
{
	LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16);
	LPC_IOCON->PIO2_0 &= ~0x07;
	LPC_IOCON->PIO2_0 |= 0x00;
	LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<16);
	LPC_GPIO2->DIR |= (1<<0);
	LPC_GPIO2->DATA |= (1<<0);
}

void Delayms(uint16_t ms)
{
	SysTick->CTRL &= ~(1<<2);
	SysTick->LOAD = SystemCoreClock/2/1000*ms-1;
	SysTick->VAL = 0;
	SysTick->CTRL = ((1<<1)|(1<<0));
	while(!ticks);
	ticks = 0;
	SysTick->CTRL = 0;
}

void Delayus(uint16_t us)
{
	SysTick->CTRL &= ~(1<<2);
	SysTick->LOAD =25*us-1;
	SysTick->VAL = 0;
	SysTick->CTRL =((1<<1)|(1<<0));
	while(!ticks);
	ticks =0;
	SysTick->CTRL =0;
}

void SysTick_Handler(void)
{
	ticks++;
}

int main(void)
{
	LedInit();
	while(1)
	{
		LED1_ON();
		Delayms(500);
		LED1_OFF();
		Delayms(500);
	}
}
